package com.flea.hclv.controller;

import com.alibaba.fastjson.JSON;
import com.flea.hclv.model.entity.HQrManage;
import com.flea.hclv.service.HQrManageService;
import com.flea.hclv.util.ServerResponse;
import com.flea.system.bean.FleaPage;
import com.flea.system.entity.OrgDept;
import com.flea.system.platform.session.FleaOrgUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @program: project
 * @description: 二维码管理
 * @author: shiliqiang
 * @create: 2018-11-01 11:13
 * @version: 1.0
 */
@Controller
@RequestMapping("/flea/hclv/qr/manage/")
public class HQrManageController {

    private Logger logger = LoggerFactory.getLogger(HQrManageController.class);

    @Autowired
    private HQrManageService hQrManageService;

    @RequestMapping("save")
    @ResponseBody
    public ServerResponse<String> save(HttpServletRequest request, HttpServletResponse response, String model){
        String userId = FleaOrgUtils.getCurUserUuid(request);
        OrgDept currentUserDept = FleaOrgUtils.getCurrentUserDept(request);
        ServerResponse<String> serverResponse = hQrManageService.save(userId,currentUserDept,model);
        return serverResponse;
    }
    @RequestMapping("update")
    @ResponseBody
    public ServerResponse<String> update(HttpServletRequest request,HttpServletResponse response,String model){
        String userId = FleaOrgUtils.getCurUserUuid(request);
        ServerResponse<String> serverResponse =hQrManageService.update(userId,model);
        return serverResponse;
    }

    //获取当前用户的所有账户信息
    @RequestMapping("selectByUserId")
    @ResponseBody
    public ServerResponse<List<HQrManage>> selectByUserId(HttpServletRequest request){
        String userId = FleaOrgUtils.getCurUserUuid(request);
        return hQrManageService.selectByUserId(userId);
    }

    /**
     * 获取导游账户
     * @param guideId  导游审核信息ID
     * @return LIST
     */
    @RequestMapping("selectByGuideId")
    @ResponseBody
    public ServerResponse<List<HQrManage>> selectByGuideId(HttpServletRequest request,String guideId){
        OrgDept currentUserDept = FleaOrgUtils.getCurrentUserDept(request);
        ServerResponse<List<HQrManage>> response = hQrManageService.selectByGuideId(guideId,currentUserDept);
        logger.info("导游账号：{}",response);
        return response;
    }

    @RequestMapping("selectById")
    @ResponseBody
    public ServerResponse<HQrManage> selectById(String id){
        return hQrManageService.selectById(id);
    }

    @RequestMapping("deleteByIds")
    @ResponseBody
    public ServerResponse<String> delete(HttpServletResponse response,String ids){
        List<String> idList = JSON.parseArray(ids,String.class);
        ServerResponse<String> serverResponse = hQrManageService.delete(idList);
        return serverResponse;
    }
    //游客支付后 显示的组团社的二维码
    @RequestMapping("getQrPath")
    @ResponseBody
    public ServerResponse<List<HQrManage>> getQrPath(HttpServletRequest request){
        OrgDept currentUserDept = FleaOrgUtils.getCurrentUserDept(request);
        ServerResponse<List<HQrManage>> data = hQrManageService.getQrPath(currentUserDept);
        logger.info("返回支付账号：{}",data);
        return data;
    }
    //显示组团社的 支付宝 微信的二维码
    @RequestMapping("selectByDeptId")
    @ResponseBody
    public ServerResponse<List<HQrManage>> getQrList(HttpServletRequest request){
        OrgDept currentUserDept = FleaOrgUtils.getCurrentUserDept(request);
        return hQrManageService.getQrListByDeptId(currentUserDept);
    }

    //显示供应商 支付宝 车队 微信的二维码
    @RequestMapping("selectByGDeptId")
    @ResponseBody
    public ServerResponse<List<HQrManage>> selectByGDeptId(String deptId){
        OrgDept currentUserDept = new OrgDept();
        currentUserDept.setDeptUuid(deptId);
        return hQrManageService.getQrListByDeptId(currentUserDept);
    }

    @RequestMapping("selectAll")
    @ResponseBody
    public ServerResponse<FleaPage<HQrManage>> getAll(@RequestParam(value = "personName", required = false) String personName, FleaPage<HQrManage> paging){
        if (paging==null){
            return ServerResponse.createByErrorMessage("分页参数错误");
        }
        //现在只可以按联系人查询
        return hQrManageService.getAll(personName,paging.getCurPage(),paging.getPageSize());
    }
    //获取车队二维码
//    @RequestMapping("selectFleet")
//    @ResponseBody
//    public ServerResponse<FleaPage<HQrManage>> selectFleet(FleaPage<HQrManage> paging,String deptId){
//        if (paging==null){
//            return ServerResponse.createByErrorMessage("分页参数错误");
//        }
//        return hQrManageService.selectFleet(paging,carReverseId);
//    }





}
